package com.blb.hello;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 打招呼自动配置类
 */
//通过HelloProperties读取配置文件
@EnableConfigurationProperties(HelloProperties.class)
@Configuration
public class HelloAutoConfiguration {

    private HelloProperties helloProperties;

    //通过构造方法注入helloProperties对象
    public HelloAutoConfiguration(HelloProperties helloProperties) {
        this.helloProperties = helloProperties;
    }

    //对外界提供hello服务对象
    @Bean
    //执行条件，没有该对象再调用
    @ConditionalOnMissingBean
    public HelloService helloService(){
        //返回的对象交给IOC容器
        return new HelloService(helloProperties);
    }
}
